package com.example.demo.controller;

import com.example.demo.domain.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.*;

//返回指定文件，RestController返回具体值
@Controller
public class StudentController {
    private HashMap<String,Student> map = new HashMap<>();

    //RequestBody
    @GetMapping("/student")
    public String getStudent(@RequestBody Student student, Model model){
        map.put("1",student);
        model.addAttribute("map",map.get("1"));
        System.out.println(model.getAttribute("map"));
     return "hello";
    }
    //RequestParam
    @PutMapping("/student2")
    public String putStudent(@RequestParam(value = "name",defaultValue = "默认") String name,@RequestParam(value = "no",defaultValue = "4014") int no, Model model){

        Student student = new Student(no,name);
        student.setName("修改后");
        map.put("2",student);
        model.addAttribute("map",map.get("2"));

        return "hello";
    }
}
